package com.xy.user.service;


import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import com.xy.user.domain.Xycolumn;
import com.xy.user.persistence.XycolumnMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * 表属性
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class XycolumnService extends BaseService<Xycolumn> {
    @Autowired
    private XycolumnMapper xycolumnMapper;

    @Autowired
    public void setBaseMapper(XycolumnMapper xycolumnMapper) {
        this.baseMapper = xycolumnMapper;
    }

    public List<Map<String,Object>> getListTableId(Map<String, Object> param) {
        return xycolumnMapper.listTableId(param);
    }

    public void checkEntity(Xycolumn xycolumn) throws ClassCheckException {
        if(xycolumn.getColumnId()!=null&&xycolumn.getColumnId().length()>19){
            throw new ClassCheckException("表属性主键不能超过19个字符");
        }
        if(xycolumn.getName()!=null&&xycolumn.getName().length()>19){
            throw new ClassCheckException("表属性属性名不能超过19个字符");
        }
        if(xycolumn.getTableId()!=null&&xycolumn.getTableId().length()>19){
            throw new ClassCheckException("表属性表名不能超过19个字符");
        }
        if(xycolumn.getDefalt()!=null&&xycolumn.getDefalt().length()>19){
            throw new ClassCheckException("表属性默认值不能超过19个字符");
        }
        if(xycolumn.getDescribe()!=null&&xycolumn.getDescribe().length()>50){
            throw new ClassCheckException("表属性中文解释不能超过50个字符");
        }
    }
    public void checkListEntity(List<Xycolumn> listXycolumn) throws ClassCheckException {

        for (Xycolumn xycolumn : listXycolumn) {
            checkEntity(xycolumn);
        }

    }
}
